package user

import (
	"encoding/json"
	"fmt"
	"gin/app/http/global"
	user2 "gin/app/http/model/user"
	"gin/app/http/response"
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
	"net/http"
)

func Index(c *gin.Context) {
	username, _ := c.Get("user_name")
	c.JSON(http.StatusOK, gin.H{
		"code": 1,
		"msg":  "请求成功!",
		"data": "首页",
		"extend": gin.H{
			"username": username,
		},
	})
}

// 获取用户信息
func GetUserInfo(c *gin.Context) {

	token, _ := c.Get("token")
	fmt.Println(1111, token)
	prefix := viper.GetString("redis.prefix")
	Rdb := global.Rdb
	str, err := Rdb.HGet(c, prefix+"_user_info", token.(string)).Result()
	var userInfo user2.UserModel
	if err == nil {
		err := json.Unmarshal([]byte(str), &userInfo)
		if err == nil {
			response.Success(c, "请求成功", gin.H{
				"userInfo": userInfo,
			})
			return
		}
	}
	response.Fail(c, err.Error(), gin.H{})
}
